home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4905 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.1 KB

  1. Path: bmtlh10.bnr.ca!news
  2. From: John Hickin <hickin@bnr.ca>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Compile problem
  5. Date: 1 Feb 1996 14:58:58 GMT
  6. Organization: Bell-Northern Research
  7. Message-ID: <4eqkfi$fl8@bmtlh10.bnr.ca>
  8. References: <4eol9k$gqf@fred.uswnvg.com>
  9. NNTP-Posting-Host: bmtlh520.bnr.ca
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1 (X11; I; HP-UX A.09.05 9000/715)
  14. X-URL: news:4eol9k$gqf@fred.uswnvg.com
  15.  
  16. This happens with gotos and often happens in switch statements which are
  17. disguised gotos.  Essentially the compiler has determined that you are using an
  18. object without having constructed it.  Consider the following:
  19.  
  20. switch(type)
  21. { case 1: int x = 1; ...
  22.   case 2: ++x;
  23. etc.
  24. }
  25.  
  26. and watch what happens if type != 1.
  27.  
  28. One solution uses a separate block for each case:
  29.  
  30.    case 1: { int x = 1; ... }
  31.  
  32. The other 'promotes' the scope of x (define it before the switch).  Which
  33. one you use depends whether or not x must be accessed by more than one case.
  34.  
  35. -- 
  36. John Hickin      Bell-Northern Research, Montreal, Quebec
  37. (514) 765-7924   hickin@bnr.ca
  38.  
  39.